package cn.iocoder.yudao.module.wine.dal.mysql.suggest;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.wine.controller.app.suggest.vo.AppSuggestRespVO;
import cn.iocoder.yudao.module.wine.dal.dataobject.suggest.SuggestDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplytype.SupplyTypeDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.wine.controller.admin.suggest.vo.*;

/**
 * 用户建议 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface SuggestMapper extends BaseMapperX<SuggestDO> {

    default PageResult<SuggestRespVO> selectPage(SuggestPageReqVO reqVO) {
        return selectJoinPage(reqVO,SuggestRespVO.class, new MPJLambdaWrapperX<SuggestDO>()
                .eqIfPresent(SuggestDO::getUserId, reqVO.getUserId())
                .eqIfPresent(SuggestDO::getContent, reqVO.getContent())
                .eqIfPresent(SuggestDO::getImages, reqVO.getImages())
                .eqIfPresent(SuggestDO::getSupplyTypeId, reqVO.getSupplyTypeId())
                .betweenIfPresent(SuggestDO::getCreateTime, reqVO.getCreateTime())
                .leftJoin(MemberUserDO.class,MemberUserDO::getId,SuggestDO::getUserId)
                .leftJoin(SupplyTypeDO.class,SupplyTypeDO::getId,SuggestDO::getSupplyTypeId)
                .selectAll(SuggestDO.class)
                .selectAs(MemberUserDO::getNickname,SuggestRespVO::getNickname)
                .selectAs(MemberUserDO::getName,SuggestRespVO::getName)
                .selectAs(SupplyTypeDO::getTypeName,SuggestRespVO::getSupplyTypeName)
                .orderByDesc(SuggestDO::getId));
    }

    default List<AppSuggestRespVO> getMySuggestList(){
        return selectJoinList(AppSuggestRespVO.class, new MPJLambdaWrapperX<SuggestDO>()
                .eqIfPresent(SuggestDO::getUserId, SecurityFrameworkUtils.getLoginUserId())
                .leftJoin(SupplyTypeDO.class, SupplyTypeDO::getId,SuggestDO::getSupplyTypeId)
                .selectAll(SuggestDO.class)
                .selectAs(SupplyTypeDO::getTypeName,AppSuggestRespVO::getSupplyTypeName)
                .orderByDesc(SuggestDO::getCreateTime));
    }
}
